﻿using CarAppDomain.CarType.IService;
using CarAppDto.CarType.SalesCarTypeDtos;
using D.UtilCore.Dtos;
using D.UtilCore.Filters;
using D.UtilCore;
using D.UtilSqlsugarOrm;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using CarAppDto.CarType.VehicleSeriesDtos;
using CarAppDto.CarParts.CarPartsDtos;

namespace CarAppAPI
{
    [Route("/api/[controller]/[action]")]
    [Authorize]
    public class VehicleSeriesController : BaseApiController
    {
        private readonly IVehicleSeriesService _service;
        public VehicleSeriesController(IVehicleSeriesService service)
        {
            _service = service;
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="reqModel"></param>
        /// <returns></returns>
        [HttpPost, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<int>> Add([FromBody] ReqAddVehicleSeries reqModel)
        {
            reqModel.CreateUser = Account;
            return await _service.AddVehicleSeriesAsync(reqModel);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("{ids}"), TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<int>> Delete(string ids)
        {
            var idsArray = ids.Split(",");
            return await _service.DeleteVehicleSeriesAsync(idsArray.ToList());
        }

        /// <summary>
        /// 修改
        /// </summary> 
        /// <param name="reqModel"></param>
        /// <returns></returns>
        [HttpPut, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<int>> Update([FromBody] ReqUpdateVehicleSeries reqModel)
        {
            reqModel.UpdateUser = Account;
            return await _service.UpdateVehicleSeriesAsync(reqModel);
        }

        /// <summary>
        /// 获取详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}"), TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<RepVehicleSeries>> Get(string? id)
        {
            return await _service.GetVehicleSeriesAsync(id);
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="reqModel"></param>
        /// <returns></returns>
        [HttpPost, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<List<RepVehicleSeries>>> List([FromBody] ReqQueryVehicleSeriesList reqModel)
        {
            return await _service.QueryVehicleSeriesListAsync(reqModel);
        }

        /// <summary>
        /// 分页
        /// </summary>
        /// <returns></returns>
        [HttpPost, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<PageModel<RepVehicleSeries>>> Pages([FromBody] ReqQueryVehicleSeriesPage reqQueryPage)
        {
            return await _service.QueryVehicleSeriesPagesAsync(reqQueryPage);
        }

        /// <summary>
        /// 删除配件
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("{ids}"), TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<int>> DeleteCarParts(string ids)
        {
            var idsArray = ids.Split(",");
            return await _service.DeleteCarParts(idsArray.ToList());
        }

        /// <summary>
        /// 新增配件
        /// </summary>
        /// <param name="reqModel"></param>
        /// <returns></returns>
        [HttpPost, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<int>> AddCarParts([FromBody] ReqCarPartsVehicleSeries reqModel)
        {
            return await _service.AddCarParts(reqModel, Account);
        }

        /// <summary>
        /// 获取配件
        /// </summary>
        /// <returns></returns>
        [HttpPost, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<List<RepCarParts>>> CarPartsList([FromBody] ReqQueryCarPartsVehicleSeriesPage reqQueryPage)
        {
            return await _service.GetCarPartsListByVehicleSeries(reqQueryPage);
        }


    }
}
